<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core' %>
<%@ taglib prefix='fn' uri='http://java.sun.com/jsp/jstl/functions' %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%
    /**
     * @Description :  General Board form comment
     * @Modification Information
     *
     *   수정일               수정자                   수정내용
     *  -------    --------    ---------------------------
     *
     *
     */
%>
<script type="text/javascript">
$(document).ready(function() {
//********************************************************
// Validate define area   
//********************************************************    
//TODO .validate 공통으로 빼기
    $("#formComment").validate({
        rules: {},
        messages:{},
        //submitHandler: Form1.registForm,
        showErrors:function(errorMap, errorList){
            this.defaultShowErrors();
        },
        invalidHandler: function(event, validator) {
            var errors = validator.numberOfInvalids();
            if (errors) {
              var message = errors == 1
                ? 'You missed 1 field. It has been highlighted'
                : 'You missed ' + errors + ' fields. They have been highlighted';
              alert(validator.errorList[0].message);
            }
        } ,
    });  

    var vRules = new ValidateRules();
    vRules.addRules("#writer_id", "작성자ID");
    vRules.addRules("#writer_nm", "작성자명");
    vRules.addRules("#cmmt_contents", "내용");
    vRules.addRules("#passwd", "비밀번호");
});
</script>

<strong>댓글작성</strong>

<form id="formComment" name="formComment" method="post">
<table id="tblComment"  width="100%" border="0" cellpadding="0" cellspacing="1" summary="댓글">
    <colgroup>
        <col width="14%"/>
        <col width="16%"/>
        <col width="20%"/>
        <col width="14%"/>
        <col width="16%"/>
        <col width="20%"/>
    </colgroup>
    <tbody>
        <tr>
            <td>
                <label for="writer_id">작성자ID</label>
            </td>
            <td>
                <input id="writer_id" name="writer_id" type="text" readonly="readonly" value="${sessionScope.userInfo.userId}"/>
            </td>
            <td>
                <label for="writer_nm">작성자명</label>
            </td>
            <td>
                <input id="writer_nm" name="writer_nm" type="text" value="${sessionScope.userInfo.userId}"/>
            </td>
            <td>
                <label for="passwd">비밀번호</label>
            </td>
            <td>
                <input id="passwd" name="passwd" type="password"/>
            </td>
        </tr>
        <tr>
            <td colspan="3"><div id="divCmmtReplyDesc"></div></td>
            <td colspan="3"></td>
        </tr> 
        <tr>
            <td colspan="6">
                <textarea id="cmmt_contents" name="cmmt_contents" placeholder="" style="width:80%;height:100px;"></textarea>
            </td>           
        </tr>             
    </tbody>
</table>
</form>

<c:if test="${fn:length(listCmmt) > 0}">
    <strong>댓글</strong>&nbsp;(총&nbsp;<c:out value="${fn:length(listCmmt)}"/>개)
    <table width="100%" border="0" cellpadding="0" cellspacing="1" summary="댓글">
        <colgroup>
            <col width="30%"/>
            <col width="20%"/>
            <col width="50%"/>
        </colgroup>
        <tbody>
        <c:forEach var="row" items="${listCmmt}" varStatus="status">
            <tr>
                <td>
                    <c:if test="${row.DEPTH != 0}">
                        <c:forEach begin="0" end="${row.DEPTH}" step="1">&nbsp;</c:forEach>
                        <!--<span><img src="<c:url value='/resources/images/bbs/reply_arrow.gif'/>"></span>-->
                        <span><img src="<c:url value='/resources/images/bbs/i_memo_reply.gif'/>"></span>
                    </c:if>                 
                    <strong><c:out value="${row.WRITER_NM}(${row.WRITER_ID})"/></strong>
                </td>
                <td><c:out value="${row.CREATE_DATE}"/></td>
                <td class="left">
                    <a href="javascript:deleteComment(<c:out value="${row.CMMT_ID}"/>);" title="댓글을 삭제합니다.">X</a>
                    <a href="javascript:replyCommentMark(<c:out value="${row.CMMT_ID}"/>);" title="댓글에 답변을 답니다.">R</a>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <div id="divContents-${row.CMMT_ID}"><c:out value="${row.CONTENTS}"/></div>
                    <div id="divCmmtId-${row.CMMT_ID}" style="display:none"><c:out value="${row.CMMT_ID}"/></div>
                    <div id="divThread-${row.CMMT_ID}" style="display:none"><c:out value="${row.THREAD}"/></div>
                    <div id="divDepth-${row.CMMT_ID}" style="display:none"><c:out value="${row.DEPTH}"/></div>
                    <div id="divOrderSeq-${row.CMMT_ID}" style="display:none"><c:out value="${row.ORDER_SEQ}"/></div>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</c:if>

